<template>
	<view style="text-align: center;color: #FFFFFF;">
		
		<view style="text-align: center;color: #FFFFFF;padding-top: 8px;padding-bottom:8px;font-size: 16px;font-weight: bold">
			会员特权
		</view>
		
		<view style="margin-top: 2px">
			1、会员购买商品可享受省钱 +返现！
		</view>
		<view style="margin-top: 2px">
			2、会员分享商品给好友购买拿佣金！
		</view>
		
		<view class="buy-box-center">
			<view class="code-cent" style="margin-top: 10px;">
				<div class="cente-text" style="height: auto;">
					<div>
						<view class="textarea" style="height: auto;">{{ tkl }}</view>
					</div>
				</div>
			</view>
			<button class="buy-btn-copy" v-bind:class="[copyTklStatus ? 'active' : 'active', '']" @tap="copyTklWenAn">
				{{ copyTklStatus ? ' 复制成功！请打开【手机淘宝】进行授权' : '一键复制' }}
			</button>
			<view style="margin-top: 2px">
				{{ tbAuhorizeResult }}
			</view>
		</view>
		

		<view id="shareit" v-if="show_share" @tap="closeShare">
			<image class="arrow" src="../../static/img/jiant.png"></image>
			<view id="follow">受微信平台限制无法进行会员申请！点击右上角按钮，选择浏览器打开！授权成功后请自行返回微信！</view>
		</view>
	</view>
</template>

<script>
	var _this;
	let userId = null;
	let authorizeNotice = false;
	//const plug = uni.requireNativePlugin('Html5app-Baichuan'); 
	export default {
		data() {
			return {
				weiXin: false,
				description: "立即申请",
				show_share: false,
				des: "",
				timer: null,
				userInfo: "userInfo",
				relation_id: '',
				copyTklStatus: false,
				tkl : "",
				tbAuhorizeResult : ""
			}
		},
		onPullDownRefresh: function() {
			uni.stopPullDownRefresh(); // 停止刷新
		},
		onUnload: function() {
			if (this.timer) {
				clearInterval(this.timer);
				this.timer = null;
			}
		},
		onLoad() {
			//#ifdef H5
			let ua = navigator.userAgent.toLowerCase();
			if (ua.indexOf('micromessenger') !== -1) {
				this.weiXin = true;
				if (window.location.href.indexOf("?uid=") !== -1 && window.location.href.indexOf("&time=order") === -1 && window.location
					.href.indexOf("&code=") === -1) {
					window.location.href = window.location.href + "&time=order";
				}
				if (window.location.href.indexOf("?uid=") === -1 && window.location.href.indexOf("?time=order") === -1 && window.location
					.href.indexOf("&code=") === -1) {
					window.location.href = window.location.href + "?time=order";
				}
			} else {
				if (window.location.href.indexOf("?code=") !== -1 || window.location.href.indexOf("&code=") !== -1) {
					let code;
					if (window.location.href.indexOf("?code=") !== -1) {
						code = window.location.href.split("?code=")[1].split("&")[0];
					} else {
						code = window.location.href.split("&code=")[1].split("&")[0];
					}
					this.getUserInfo(code);
				}
				if (window.location.href.indexOf("?uid=") !== -1 && window.location.href.indexOf("&token=") !== -1) {
					let uid = window.location.href.split("?uid=")[1].split("&")[0];
					let token = window.location.href.split("&token=")[1].split("&")[0];
					this.$queue.setData("token", token);
					this.$queue.setData("userId", uid);
					//#ifdef H5
					let ua = navigator.userAgent.toLowerCase();
					if (ua.indexOf('micromessenger') === -1) {
						this.getUserInfos(uid);
					}
					//#endif
					//#ifndef H5
					this.getUserInfos(uid);
					//#endif
				}
			}
			//#endif
		},
		onShow() {
			userId = this.$queue.getData("userId");
			console.log('成为会员的userId='+userId);
			if (!userId) {
				this.navTo('/pages/member/register');
				return;
			}
			let relation_id = this.$queue.getData("relation_id");
			if (relation_id) {
				this.relation_id = relation_id;
				this.description = "返回";
				this.des = "恭喜你已成为【好物一号】的会员！"
			} else {
				let token = this.$queue.getData("token");
				
				
				this.description = "立即申请";
			}
			
			//tb授权地址
			this.$Request.getT('/user/create_authtbapp_link?fans_id=' + userId+'&toTkl=true')
			.then(res => {
				if (res.success ) {
					this.tkl = res.data
				}else{
					this.tkl = '淘宝授权地址获取失败:'+ res.msg
				}
			})
		},
		mounted() {
			_this = this;
		},
		methods: {
			getUserInfos(userId) {
				 
			},
			checkTBAuhorrize : function(){
				setTimeout(function(){
					//tb授权结果
					_this.$Request.getT('/user/getNewRelation?fans_id=' + userId)
					.then(res => {
						if (res.success ) {
							this.$queue.setData("relation_id",res.data)
							uni.showModal({
								showCancel: false,
								title: '淘宝授权结果',
								content: '淘宝授权成功'
							});
						}else{
							_this.checkTBAuhorrize();
							_this.tbAuhorizeResult = res.msg
						}
					})
				
					console.log('检测淘宝授权')
				},2000);
			},
			copyTklWenAn: function() {
				uni.setClipboardData({
					data: this.tkl,
					success: r => {
						this.copyTklStatus = true;
						this.checkTBAuhorrize()
					}
				});
			},
			closeShare() {
				this.show_share = false;
			},
			goHome() {
 

			},


			authorized() {
			 
			},
			getUserInfoss(code) {
				 
			}

		},
	}
</script>

<style>
	@import "../../static/css/index.css";

	page {
		background: #e10a07;
	}

	#shareit {
		-webkit-user-select: none;
		position: fixed;
		/*width: 100%;*/
		height: 2000px;
		background: rgba(0, 0, 0, 0.85);
		text-align: center;
		top: 0;
		left: 0;
		z-index: 999;
	}

	#shareit img {
		max-width: 100%;
	}

	.arrow {
		width: 100px;
		height: 150px;
		position: absolute;
		right: 5%;
		top: 1%;
	}

	#follow {
		margin-right: 60px;
		margin-left: 30px;
		width: 90%;
		height: 50px;
		line-height: 50px;
		text-align: left;
		text-decoration: none;
		font-size: 18px;
		color: white;
		float: left;
		margin-top: 160px;
	}
</style>
